<?php




$debug=0;
$dbhost = "localhost";
$dbuser = "fossilplot";
$dbpass = "fossilplot";
$dbname = "fossilplot";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
//$F = $_GET['F'];
$arrGen = $_POST['arrGen'];
$arrCart = $_POST['arrCart'];



//$arrSel = $_GET['arrSel'];

//echo "array is :".$arrSel."<br>";

//echo "hello F".$F."<br>";
if($debug){
echo "hello selected Gen ".$arrGen."<br>";
echo "hello Cart ".str_replace('*','+',$arrCart)."<br>";
}
//$exploded_cart = explode(',', str_replace('*','+',$arrCart));

//$exploded_gen = explode(',', str_replace('*','+',$arrGen));


$exploded_cart = explode(',', $arrCart);

$exploded_gen = explode(',', $arrGen);


if(strpos($arrCart,$exploded_gen[0]) !== false){
	$search_gen="(";
	
}
else{
$search_gen="('".$exploded_gen[0]."'";
}
for($i=1;$i<sizeof($exploded_gen);$i++){

	
		if(strpos($arrCart,$exploded_gen[$i]) !== false){next;}
		else{
			if($search_gen=="("){
				$search_gen=$search_gen."'".$exploded_gen[$i]."'";
			}else{
	
				$search_gen=$search_gen.","."'".$exploded_gen[$i]."'";
			}
		}

}
$search_gen=$search_gen.")";



if($debug){
echo "exploded gen 3 is ".$exploded_gen[2]."<br>";
echo "size of selected gen is ".sizeof($exploded_gen)."<br>";
}
ob_flush(); flush();
if ($arrGen == null && $exploded_cart[0]=="No Items Selected"){
echo "<select name=\"G[]\" multiple size=\"63\" style=\"WIDTH: 290px\">";
echo "<option>"."No Items Selected"."</option>";
echo "</select>";
}
else{//$arrGen is not null

echo "<div id=\"select_container\" style=\"overflow-x:scroll; width:290px; overflow: -moz-scrollbars-horizontal;\" >";

echo "<select name=\"G[]\" multiple size=\"63\">";

foreach($exploded_cart as $tmp_cart){
if($tmp_cart != "No Items Selected"){
echo "<option>".$tmp_cart."</option>";
}
}



$result = mysql_query("select genus_name, phylum_name, class_name, order_name,fad_date,lad_date from genus where genus_name in $search_gen");
while ($row = mysql_fetch_array($result)) {

				echo "<option>".$row{'genus_name'}."; ".$row{'phylum_name'}."; ".$row{'class_name'}.";".$row{'order_name'}."; ".$row{'fad_date'}."; ".$row{'lad_date'}."</option>";

}




echo "</select>";

echo "</div>";
} //end of else ($arrGen is not null)


?>